package com.sailfish.template.infra.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author XIAXINYU3
 * @date 2021.11.1
 */
@Configuration
public class ThreadPoolConfig {
    /**
     * 业务执行器
     */
    public static final String BUSINESS_SERVICE_EXECUTOR = "bizService";

    /**
     * 用于业务执行器
     *
     * @return 线程池
     */
    @Bean(name = BUSINESS_SERVICE_EXECUTOR)
    public AsyncTaskExecutor asyncBusinessServiceExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setThreadNamePrefix(BUSINESS_SERVICE_EXECUTOR + "-");
        //后续可根据实际业务或者CPU核数进行设置
        executor.setCorePoolSize(3);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(99999);
        return executor;
    }
}
